import Vue from "vue";
import Router from "vue-router";

const Home = () => import('../views/home/Home.vue');
const Category = () => import('../views/category/Category.vue');
const Cart = () => import('../views/cart/Cart.vue');
const Profile = () => import('../views/profile/Profile.vue');

Vue.use(Router);

const routes = [
  {
    path: "",
    redirect: "/home"
  },
  {
    path: "/home",
    component: Home,
    meta: {
      title: '首页'
    }
  },
  {
    path: "/category",
    component: Category,
    meta: {
      title: '商品分类'
    }
  },
  {
    path: "/cart",
    component: Cart,
    meta: {
      title: '我的购物车'
    }
  },
  {
    path: "/profile",
    component: Profile,
    meta: {
      title: '个人信息'
    }
  }
];

const router = new Router({
  routes,
  mode: "history"
});

export default router;

router.beforeEach((to, from, next) => {
  document.title = to.matched[0].meta.title;
  next();
});
